import com.dmotiko.general.*
import com.dmotiko.bolacua.*
import mx.utils.Delegate;

class RoomComponent
extends BaseClip {
	
	private var txtTitle:TextField;
	private var txtDescription:TextField;
	private var mcTarifas:MovieClip;
	private var mcIcon:MovieClip;
	private var mcPhotoList:RoomPhotoList;
	private var mcRoomFeatures:RoomFeatureComponent;
	
	private function RoomComponent() {
		super();
		
		txtTitle.autoSize = "left";
		mcTarifas.onRelease = function() {
			BolacuaSite.getApp().setSection( BolacuaSite.TARIFAS );
		}
	}
	
	private function refreshData():Void {
		var room:RoomData = RoomData(data);
		txtTitle.text = room.getTitle();
		txtDescription._x = txtTitle._x + txtTitle._width + 3;
		txtDescription.text = room.getDescription();
				
		mcIcon.loadMovie( room.getIcon());
		
	}
	
	public function childLoaded(evnt):Void {
		var room:RoomData = RoomData(data);
		if ( evnt.target == mcPhotoList) {
			mcPhotoList.addEventListener( BaseClipEvent.CHANGED, Delegate.create(this, photoSelected) );
			mcPhotoList.setData( room.getPhotos() );
		} else if ( evnt.target == mcRoomFeatures) {
			mcRoomFeatures.setData( room.getFeatures() );
		}
	}
	
	private function photoSelected(evnt):Void {
		BolacuaSite.getApp().getPhotoPopUp().setData( { index: evnt.index, photos: evnt.target.getData() } );
	}
	
}